package com.woniu.zsd.recycle.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniu.zsd.common.util.JWTUtil;
import com.woniu.zsd.common.util.Result;
import com.woniu.zsd.recycle.form.AddComplaintForm;
import com.woniu.zsd.recycle.form.ReplyComplaintForm;
import com.woniu.zsd.recycle.param.AddComplaintParam;
import com.woniu.zsd.recycle.param.ReplyComplaintParam;
import com.woniu.zsd.recycle.service.ComplaintService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 彭于晏
 * @since 2025年02月18日
 */
@RestController
@RequestMapping("/complaint")
@Api(tags = "投诉管理")
public class ComplaintController {
    @Resource
    private ComplaintService complaintService;

    @PostMapping("/addComplaint")
    @ApiOperation(value = "新增用户投诉")
    public Result addComplaint(@RequestBody AddComplaintForm form)throws Exception{
        complaintService.addComplaint(BeanUtil.toBean(form, AddComplaintParam.class));
        return Result.success("用户投诉成功", null);
    }
    @PostMapping("/replyComplaint")
    @ApiOperation(value = "站点回复投诉")
    public Result replyComplaint(@RequestBody ReplyComplaintForm form)throws Exception{
        complaintService.replyComplaint(BeanUtil.toBean(form, ReplyComplaintParam.class));
        return Result.success("站点回复投诉成功", null);
    }
    @PostMapping("/selectComplaintByStationId")
    @ApiOperation(value = "根据站点ID查询投诉")
    public Result selectComplaintByStationId(Integer stationId)throws Exception{
        return Result.success("站点查询投诉成功", complaintService.selectComplaintByStationId(stationId));
    }
    @PostMapping("/selectComplaintByUserId")
    @ApiOperation(value = "根据用户ID查询投诉")
    public Result selectComplaintByUserId(Integer userId)throws Exception{
        return Result.success("站点查询投诉成功", complaintService.selectComplaintByUserId(userId));
    }
    @PostMapping("/solveComplaint")
    @ApiOperation(value = "解决投诉")
    public Result solveComplaint(Integer complaintId)throws Exception{
        complaintService.solveComplaint(complaintId);
        return Result.success("投诉成功解决", null);
    }
    @PostMapping("/cancelComplaint")
    @ApiOperation(value = "用户撤销投诉")
    public Result cancelComplaint(Integer complaintId)throws Exception{
        complaintService.cancelComplaint(complaintId);
        return Result.success("用户撤销投诉成功", null);
    }
}

